package com.ruoyi.project.WebMoudle.advShow.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.advShow.domain.AdvShow;
import com.ruoyi.project.WebMoudle.advShow.service.IAdvShowService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 店铺广告Controller
 * 
 * @author ruoyi
 * @date 2020-07-02
 */
@Controller
@RequestMapping("/advShow/advShow")
public class AdvShowController extends BaseController
{
    private String prefix = "advShow/advShow";

    @Autowired
    private IAdvShowService advShowService;

    @RequiresPermissions("advShow:advShow:view")
    @GetMapping()
    public String advShow()
    {
        return prefix + "/advShow";
    }
    @RequiresPermissions("advShow:advShow:view")
    @GetMapping("/showSuccess")
    public String showSuccess()
    {
        return prefix + "/showSuccess";
    }
    @RequiresPermissions("advShow:advShow:view")
    @GetMapping("/showFail")
    public String showFail()
    {
        return prefix + "/showFail";
    }
    /**
     * 查询店铺广告列表
     */
    @RequiresPermissions("advShow:advShow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AdvShow advShow)
    {
        startPage();
        List<AdvShow> list = advShowService.selectAdvShowList(advShow);
        return getDataTable(list);
    }

    /**
     * 导出店铺广告列表
     */
    @RequiresPermissions("advShow:advShow:export")
    @Log(title = "店铺广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AdvShow advShow)
    {
        List<AdvShow> list = advShowService.selectAdvShowList(advShow);
        ExcelUtil<AdvShow> util = new ExcelUtil<AdvShow>(AdvShow.class);
        return util.exportExcel(list, "advShow");
    }

    /**
     * 新增店铺广告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存店铺广告
     */
    @RequiresPermissions("advShow:advShow:add")
    @Log(title = "店铺广告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AdvShow advShow)
    {
        return toAjax(advShowService.insertAdvShow(advShow));
    }

    /**
     * 修改店铺广告
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AdvShow advShow = advShowService.selectAdvShowById(id);
        mmap.put("advShow", advShow);
        return prefix + "/edit";
    }

    /**
     * 修改保存店铺广告
     */
    @RequiresPermissions("advShow:advShow:edit")
    @Log(title = "店铺广告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AdvShow advShow)
    {
        return toAjax(advShowService.updateAdvShow(advShow));
    }

    /**
     * 删除店铺广告
     */
    @RequiresPermissions("advShow:advShow:remove")
    @Log(title = "店铺广告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(advShowService.deleteAdvShowByIds(ids));
    }

    @RequiresPermissions("advShow:advShow:edit")
    @RequestMapping("/changText1")
    @ResponseBody
    public AjaxResult changText1 (AdvShow advShow){
        return toAjax(advShowService.updateAdvShow(advShow));
    }
}
